//package com.amigo.online.provider.search.service.impl;
//
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.LinkedHashMap;
//import java.util.List;
//import java.util.Map;
//
//import javax.annotation.Resource;
//
//import org.apache.solr.client.solrj.SolrClient;
//import org.apache.solr.common.SolrInputDocument;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.ResponseEntity;
//import org.springframework.stereotype.Service;
//
//import com.amigo.online.common.core.response.Response;
//import com.amigo.online.provider.search.model.SearchResponseResult;
//import com.amigo.online.provider.search.service.MusicFeignService;
//import com.amigo.online.provider.search.service.SearchItemService;
//import com.amigo.online.provider.search.service.UserFeignService;
//import com.amigo.online.provider.search.service.VideoFeignService;
//@Service
//public class SearchItemServiceImpl implements SearchItemService{
//	@Resource(name="SolrClient_user") 
//	private SolrClient SolrClient_user;
//	@Resource(name="SolrClient_video") 
//	private SolrClient SolrClient_video;
//	@Resource(name="SolrClient_music") 
//	private SolrClient SolrClient_music;
//	@Autowired
//	private MusicFeignService musicFeignService;
//    @Autowired
//    private VideoFeignService videoFeignService;
//    @Autowired
//    private UserFeignService  userFeignService;
//	@Override
//	public SearchResponseResult importAllDataIndex()
//			throws Exception {
//		ResponseEntity<Response> musicResponse = musicFeignService.getAll();
//		ResponseEntity<Response> videoResponse = videoFeignService.getAll();
//		ResponseEntity<Response> userResponse = userFeignService.getAll();
//		
//		@SuppressWarnings("unchecked")
//		List<LinkedHashMap<?,?>> data1 = (List<LinkedHashMap<?,?>>)musicResponse.getBody().getData();
//		//data1转map
//		Map<String,LinkedHashMap<?,?>> musicMap=new HashMap<String,LinkedHashMap<?,?>>();
//		if(data1 != null) {			
//			for(LinkedHashMap<?,?> map:data1){
//				musicMap.put(map.get("id")+"", map);
//			}
//		}
//		@SuppressWarnings("unchecked")
//		List<LinkedHashMap<?,?>> data2 = (List<LinkedHashMap<?,?>>)videoResponse.getBody().getData();
//		@SuppressWarnings("unchecked")
//		List<LinkedHashMap<?,?>> data3 = (List<LinkedHashMap<?,?>>)userResponse.getBody().getData();
//		//data3转map
//		Map<String,LinkedHashMap<?,?>> userMap=new HashMap<String,LinkedHashMap<?,?>>();
//		System.out.println("userMap is null"+userMap == null);
//		if(data3 != null) {		
//			for(LinkedHashMap<?,?> map:data3){
//				
//					//System.out.println(map.get("id"));
//				
//				userMap.put(map.get("id")+"",map);
//			}
//		}
//		/*//音乐库暂取消
//		if(data1!=null){
//			//为文档添加域
//			List<SolrInputDocument> doc=new ArrayList<SolrInputDocument>();
//			// 4、为文档添加域
//			for(LinkedHashMap<?,?> map:data1){
//				SolrInputDocument document = new SolrInputDocument();
//				document.addField("id",map.get("id")+"");//音乐ID
//				document.addField("music_name", map.get("name")+"");//音乐名称
//				document.addField("music", map.get("music")+"");//音乐地址
//				document.addField("cover", map.get("cover")+"");//音乐封面
//				document.addField("recommended",map.get("recommended")+"");//音乐评论
//				document.addField("video_id",map.get("videoId") +"");//对应视频地址
//				document.addField("created_time", map.get("createdTime")+"");//创建时间
//				doc.add(document);
//			}
//			SolrClient_music.add(doc);
//			// 5、向索引库中添加文档。
//			SolrClient_music.commit();
//		}*/
//		   
//	    //视频库
//		if(data2!=null){
//			//为文档添加域
//			List<SolrInputDocument> doc1=new ArrayList<SolrInputDocument>();
//			// 4、为文档添加域
//			for(LinkedHashMap<?,?> map:data2){
//				SolrInputDocument document = new SolrInputDocument();
//				document.addField("id", map.get("id")==null?"":map.get("id")+"");//视频id
//				document.addField("userId", map.get("userId")==null?"":map.get("userId")+"");//用户id
//				document.addField("video", map.get("video")==null?"":map.get("video")+"");//视频地址
//				document.addField("cover", map.get("cover")==null?"":map.get("cover")+"");//封面
//				document.addField("duration", map.get("duration")==null?"":map.get("duration")+"");//封面
//				document.addField("href", map.get("href")==null?"":map.get("href")+"");//跳转地址
//				document.addField("type", map.get("type")==null?"":map.get("type")+"");//类型
//				document.addField("ads", map.get("ads")==null?"":map.get("ads")+"");//是否是广告
//				document.addField("recommended", map.get("recommended")==null?"":map.get("recommended")+"");//推荐
//				document.addField("up", map.get("up")==null?"":map.get("up")+"");//点赞数量
//				document.addField("look", map.get("look")==null?"":map.get("look")+"");//观看数量
//				document.addField("comment", map.get("comment")==null?"":map.get("comment")+"");//评论数量
//				document.addField("contentcount", map.get("content")==null?"":map.get("content")+"");//评论内容
//				document.addField("titlename", map.get("title")==null?"":map.get("title")+"");//标题
//				document.addField("width", map.get("width")==null?"":map.get("width")+"");//宽
//				document.addField("height", map.get("height")==null?"":map.get("height")+"");//高
//				document.addField("share", map.get("share")==null?"":map.get("share")+"");//分享数
//				if(musicMap.get(map.get("musicId")+"")!=null){
//					String key=map.get("musicId")+"";
//						document.addField("id_music", musicMap.get(key).get("id")==null?"":musicMap.get(key).get("id")+"");//音乐id
//						document.addField("userId_music", musicMap.get(key).get("userId")==null?"":musicMap.get(key).get("userId")+"");//音乐用户id
//						document.addField("name_music", musicMap.get(key).get("name")==null?"":musicMap.get(key).get("name")+"");//音乐名
//						document.addField("category_music", musicMap.get(key).get("category")==null?"":musicMap.get(key).get("category")+"");
//						document.addField("cover_music", musicMap.get(key).get("cover")==null?"":musicMap.get(key).get("cover")+"");
//						document.addField("recommended_music", musicMap.get(key).get("recommended")==null?"":musicMap.get(key).get("recommended")+"");
//						document.addField("videoId_music", musicMap.get(key).get("videoId")==null?"":musicMap.get(key).get("videoId")+"");
//						document.addField("used_music", musicMap.get(key).get("used")==null?"":musicMap.get(key).get("used")+"");
//						document.addField("type_music", musicMap.get(key).get("type")==null?"":musicMap.get(key).get("type")+"");
//						document.addField("createdTime_music", musicMap.get(key).get("createdTime")==null?"":musicMap.get(key).get("createdTime")+"");
//						document.addField("music_music", musicMap.get(key).get("music")==null?"":musicMap.get(key).get("music")+"");
//					    
//					
//				}
//				if(userMap.get(map.get("userId")+"")!=null){
//						document.addField("nickname_user", userMap.get(map.get("userId")+"").get("nickname")==null?"":userMap.get(map.get("userId")+"").get("nickname")+"");
//						document.addField("avatar", userMap.get(map.get("userId")+"").get("avatar")==null?"":userMap.get(map.get("userId")+"").get("avatar")+"");
//				}
//				doc1.add(document);
//			}
//			SolrClient_video.add(doc1);
//			SolrClient_video.commit();
//		}
//		//用户库
//		if(data3!=null){
//			//为文档添加域
//			List<SolrInputDocument> doc2=new ArrayList<SolrInputDocument>();
//			// 4、为文档添加域
//			for(LinkedHashMap<?,?> map:data3){
//				SolrInputDocument document = new SolrInputDocument();
//				document.addField("id", map.get("id")+"");//视频id
//				document.addField("account", map.get("account")==null?"":map.get("account")+"");//amigo账号
//				document.addField("nickname", map.get("nickname")==null?"":map.get("nickname")+"");//昵称
//				document.addField("sex", map.get("sex")==null?"":map.get("sex")+"");//性别
//				document.addField("email", map.get("email")==null?"":map.get("email")+"");//emai
//				document.addField("mobilephone", map.get("mobilephone")==null?"":map.get("mobilephone")+"");//手机号
//				document.addField("twitter_open_id", map.get("twitter_open_id")==null?"":map.get("twitter_open_id")+"");//twitterid
//				document.addField("facebook_open_id", map.get("facebook_open_id")==null?"":map.get("facebook_open_id")+"");//
//				document.addField("wechat_open_id", map.get("wechat_open_id")==null?"":map.get("wechat_open_id")+"");//推荐
//				document.addField("country", map.get("country")==null?"":map.get("country")+"");//国家
//				document.addField("city", map.get("city")==null?"":map.get("city")+"");//城市
//				document.addField("sign", map.get("sign")==null?"":map.get("sign")+"");//签名
//				document.addField("background", map.get("background")==null?"":map.get("background")+"");//背景图片
//				document.addField("birthday", map.get("birthday")==null?"":map.get("birthday")+"");//生日
//				document.addField("avatar", map.get("avatar")==null?"":map.get("avatar")+"");//头像
//				document.addField("secret", map.get("secret")==null?"":map.get("secret")+"");//是否可见:0所有人可见，1好友可见，2所有人不可见
//				doc2.add(document);
//			}
//			SolrClient_user.add(doc2);
//			SolrClient_user.commit();
//		}
//		
//		
//		return SearchResponseResult.ok();
//	}
//	
//	
//
//}
